package zaphod.toy.gef.japanexample.editparts;

import java.util.List;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Layer;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;

import zaphod.toy.gef.japanexample.model.ContentsModel;


public class ContentsEditPart extends AbstractGraphicalEditPart
{

    @Override
    protected IFigure createFigure()
    {
        Layer figure = new Layer();
        figure.setLayoutManager( new XYLayout() );
        return figure;
    }


    @Override
    protected void createEditPolicies()
    {
        // TODO Auto-generated method stub

    }


    @Override
    protected List getModelChildren()
    {
        ContentsModel model = getCastedModel();
        // TODO Auto-generated method stub
        return model.getChildren();
    }


    private ContentsModel getCastedModel()
    {
        Object model = getModel();
        if ( model instanceof ContentsModel )
        {
            return ((ContentsModel)model);
        }
        throw new RuntimeException( "No coressponding Model : "
                + model.getClass().getName() );

    }

}
